package com.ssm.serviceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.ssm.dao.RecruitEntityMapper;
import com.ssm.entity.RecruitEntity;
import com.ssm.service.RecruitService;

import myUtils.myPage;
@Service("RecruitServiceImpl")
@Transactional
public class RecruitServiceImpl implements RecruitService {
    @Autowired
    private RecruitEntityMapper mapper;
    
	@Override
	public void save(RecruitEntity recruit) {
		mapper.insert(recruit);
		return;
	}

	@Override
	public boolean update(RecruitEntity recruit) {
		try {
			int result = mapper.updateByPrimaryKeySelective(recruit);
			System.out.print(result);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	@Override
	public List<RecruitEntity> findWithPage(Integer page, Integer pageNum) {
		PageHelper.startPage(myPage.PAGE, myPage.PAGENUM);
		try {
			List<RecruitEntity> recruits= mapper.findAll();
			return recruits;
		}finally {
			// 保证线程安全
			PageHelper.clearPage();
		}
	}

	@Override
	public List<RecruitEntity> findWithPageByStudent(String stuId, Integer page, Integer pageNum) {
		PageHelper.startPage(page, pageNum);
		try {
			List<RecruitEntity> recruits= mapper.findAllByStudent(stuId);
			return recruits;
		}finally {
			// 保证线程安全
			PageHelper.clearPage();
		}
	}

	@Override
	public List<RecruitEntity> findWithPageByCompany(String companyId, Integer page, Integer pageNum) {
		PageHelper.startPage(myPage.PAGE, myPage.PAGENUM);
		try {
			List<RecruitEntity> recruits= mapper.findAllByCompany(companyId);
			return recruits;
		}finally {
			// 保证线程安全
			PageHelper.clearPage();
		}
	}

}
